package com.taobao.taobaowidget.popupspinner.adapter;

import java.util.List;

import android.content.Context;
import android.text.TextPaint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.taobao.taobaowidget.popupspinner.BackgroundView;

public class  PopupAdapter extends BaseAdapter{
	
	private Context mContext;
	private List<String> mList;
	private int mBGColor;
	private int mTextColor;
    private int mSelectedBGColor;
	private int mSelectedTextColor;
    private int mTextSize;
	
	
	public PopupAdapter(Context context, List<String> list, int bgcolor, int textcolor, int textsize, int selectedbgcolor, int selectedtextcolor){
		this.mContext = context;
		this.mList = list;
		this.mBGColor = bgcolor;
		this.mTextColor = textcolor;
		this.mTextSize = textsize;
		this.mSelectedBGColor = selectedbgcolor;
		this.mSelectedTextColor = selectedtextcolor;
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return mList.get(pos);
	}
	
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int pos, View view, ViewGroup group){
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(view == null){
			
			view = new LinearLayout(mContext);
			TextView textview = new TextView(mContext);
			
			
			textview.setTextSize(mTextSize);
			textview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 96));
			((LinearLayout)view).addView(textview);
			textview.setBackgroundDrawable(BackgroundView.getDrawable(mBGColor, mSelectedBGColor));
//			textview.setBackgroundColor(mSelectedBGColor);
			textview.setTextColor(BackgroundView.getColorStateList(mTextColor, mSelectedTextColor));
			textview.setPadding(12, 12, 4, 12);
			TextPaint paint = textview.getPaint();
			paint.setFakeBoldText(true); 
			holder = new ViewHolder();
			holder.mHolderText = textview;
		}else{
			holder = (ViewHolder)view.getTag();
		}
		holder.mHolderText.setText(mList.get(pos));

		view.setTag(holder);
		return view;
	}
	
	class ViewHolder {
		TextView mHolderText;
	}
}
